<?php


namespace app\queue\more;


use think\facade\Log;
use think\queue\Job;

/**
 * 多任务的队列执行
 * @Title: app\queue\more$Order
 * @Package package_name
 * @Description: todo(测试订单消费者)
 * @date 2021年10月11日
 */
class Order
{

    public function taskA(Job $job, $data){
        $isJobDone = $this->_doTaskA($data);
        if ($isJobDone) {
            Log::write('执行了任务A:'.date('Y-m-d H:i:s'));
            $job->delete();
        }else{
            if ($job->attempts() > 3) {
                $job->delete();
            }
        }
    }

    public function taskB(Job $job, $data){
        $isJobDone = $this->_doTaskB($data);
        if ($isJobDone) {
            Log::write('执行了任务B:'.date('Y-m-d H:i:s'));
            $job->delete();
        }else{
            if ($job->attempts() > 2) {
                $job->release();
            }
        }
    }

    private function _doTaskA($data) {
        Log::info(date('Y-m-d H:i:s').' - TaskA - data : '.json_encode($data));
        return true;
    }

    private function _doTaskB($data) {
        Log::info(date('Y-m-d H:i:s').' - TaskB - data : '.json_encode($data));
        return true;
    }

}